using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DataAccess;
using Entity; 
namespace Business
{
    public class bOrder
    {
        public static int insertOrder(eOrder order)
        {
            DBHelper dbh = new DBHelper();

            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@OrderID", SqlDbType.VarChar);
            pr.Value = order.OrderID;
            paramList.Add(pr);

            pr = new SqlParameter("@Date", SqlDbType.DateTime);
            pr.Value = order.Date;
            paramList.Add(pr);

            pr = new SqlParameter("@Status", SqlDbType.Int);
            pr.Value = order.Status;
            paramList.Add(pr);

            pr = new SqlParameter("@CustomerID", SqlDbType.Int);
            pr.Value = order.CustomerID;
            paramList.Add(pr);

            pr = new SqlParameter("@StoreID", SqlDbType.Int);
            pr.Value = order.StoreID;
            paramList.Add(pr);

            int r = dbh.ExecuteNonQuery("insertOrder", CommandType.StoredProcedure, paramList);
            dbh.CloseConnection();
            return r;
        }

        public static int updateStatusOrders(String orderID, int status)
        {
            DBHelper dbh = new DBHelper();

            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@OrderID", SqlDbType.VarChar);
            pr.Value = orderID;
            paramList.Add(pr);

            pr = new SqlParameter("@Status", SqlDbType.Int);
            pr.Value = status;
            paramList.Add(pr);

            int r = dbh.ExecuteNonQuery("updateStatusOrders", CommandType.StoredProcedure, paramList);
            dbh.CloseConnection();
            return r;
        }

        public static int deleteOrder(String orderID)
        {
            DBHelper dbh = new DBHelper();

            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@OrderID", SqlDbType.VarChar);
            pr.Value = orderID;
            paramList.Add(pr);

            int r = dbh.ExecuteNonQuery("deleteOrder", CommandType.StoredProcedure, paramList);
            dbh.CloseConnection();
            return r;
        }

        public static DataTable getAllOrder()
        {
            DBHelper dbh = new DBHelper();
            DataTable dt = dbh.ExecuteQueryDataTable("getAllOrder", CommandType.StoredProcedure, new List<SqlParameter>());
            dbh.CloseConnection();
            return dt;
        }

        public static eOrder getOrderByID(string orderID)
        {
            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@OrderID", SqlDbType.VarChar);
            pr.Value = orderID;
            paramList.Add(pr);

            IList il = bBase.LoadQueryString(typeof(eOrder), "getOrderByID", CommandType.StoredProcedure, paramList);
            if (il.Count > 0)
            {
                return (eOrder)il[0];
            }
            else
            {
                return null;
            }
        }
    }
}
